# Maintainer: Wu Zhenyu <wuzy01@qq.com>

_realname=gdu
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=5.30.1
pkgrel=1
pkgdesc="Fast disk usage analyzer (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/dundee/gdu"
license=('spdx:MIT')
makedepends=(
  "$MINGW_PACKAGE_PREFIX-go"
  "$MINGW_PACKAGE_PREFIX-cc"
  git)
source=("$url/archive/v$pkgver/${_realname}-${pkgver}.tar.gz")
sha256sums=('ad363967b6a34e02812e4cba36bb340f377cf64a435e23f6e8e9e6b3f775220e')

prepare() {
  cd ${_realname}-${pkgver}
  mkdir -p build-${MSYSTEM}
}

build() {
  cd ${_realname}-${pkgver}
  local _DATE=$(git log -1 --pretty=%ct) # get commit date to make it REPRODUCABLE
  local _BUILDINFO="-X 'github.com/dundee/gdu/v5/build.Version=${pkgver}' \
                    -X 'github.com/dundee/gdu/v5/build.User=${PACKAGER}' \
                    -X 'github.com/dundee/gdu/v5/build.Time=${_DATE}'"

  case "${CARCH}" in
    i686|x86_64)
      GOFLAGS+=" -buildmode=pie"
      ;;
  esac

  go build \
    -trimpath \
    -mod=readonly \
    -modcacherw \
    -ldflags "-linkmode external -extldflags \"${LDFLAGS}\" ${_BUILDINFO}" \
    -o build-${MSYSTEM}/gdu \
    github.com/dundee/gdu/v5/cmd/gdu
}

package() {
  cd ${_realname}-${pkgver}
  install -Dm755 build-${MSYSTEM}/${_realname} "${pkgdir}$MINGW_PREFIX/bin/$_realname.exe"
  install -Dm644 gdu.1    "${pkgdir}$MINGW_PREFIX/share/man/man1/$_realname.1"
  install -Dm644 LICENSE.md  "${pkgdir}$MINGW_PREFIX/share/licenses/${_realname}/LICENSE"
}
